<template>
  <div>
    <form action="">
      姓名：<input type="text" v-model="name" /> <br />
      年龄：<input type="number" v-model.number="age" /><br />
      身高：<input type="number" v-model.number="tall" />(米)<br />
      体重：<input type="number" v-model.number="weight" />(公斤)<br />
      病史：<input type="text" v-model="info" /><br />
      <button @click.prevent="zhenduan">诊断</button>
      <h3>{{ result }}</h3>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      age: 0,
      tall: 0,
      weight: 0,
      info: "",
      result: "",
    };
  },
  methods: {
    zhenduan() {
      let bmi = this.weight / (this.tall * this.tall);
      if (bmi < 18.5) {
        this.result = `${this.name}，` + "你的诊断结果：体重过轻";
      } else if (bmi > 18.5 && bmi <= 24.9) {
        this.result = `${this.name}，` + "你的诊断结果：体重正常";
      } else if (bmi > 24.9 && bmi <= 29.9) {
        this.result = `${this.name}，` + "你的诊断结果：体重过重";
      } else {
        this.result = `${this.name}，` + "你的诊断结果：体重肥胖";
      }
    },
  },
  computed: {},
};
</script>

<style>
</style>